package com.hqj;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * hightchart工具类
 */
public class HightChartUtil {

    /**
     * 生成饼图
     * @return
     */
    public static String createPie(String text,String json){
        StringBuffer sb = new StringBuffer();
        sb.append("{");
            sb.append("\"chart\": {\"plotBackgroundColor\": null,\"plotBorderWidth\": null,\"plotShadow\": false,\"type\": \"pie\"},");
            sb.append("\"title\": {\"text\": \""+text+"\"},");
            sb.append("\"tooltip\": {\"pointFormat\": \"{series.name}: <b>{point.percentage:.1f}%</b>\"},");
            sb.append("\"plotOptions\": {\"pie\": {\"allowPointSelect\": true,\"cursor\": \"pointer\",\"dataLabels\": {\"enabled\": true,\"format\": \"<b>{point.name}</b>: {point.percentage:.1f} %\",\"style\": {\"color\": \"(Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'\"}}}},");
            sb.append("\"series\": [{\"name\": \"占比\",\"colorByPoint\": true,\"data\": "+json+"}]");
        sb.append("}");
        return sb.toString();
    }

    /**
     * 生成柱形，条形，线性图
     * @param text
     * @param categories
     * @param yText
     * @param series
     * @return
     */
    public static String createBLC(String text,String categories,String yText,String series,String dw){

        StringBuffer sb = new StringBuffer();
        sb.append("{");
            sb.append("\"chart\": {\"type\": \"column\"},");
            sb.append("\"title\": {\"text\": \""+text+"\"},");
            sb.append("\"subtitle\": {\"text\": \"数据来源: mysql数据库\"},");
            sb.append("\"xAxis\": {\"categories\": "+categories+",\"crosshair\": true},");
            sb.append("\"yAxis\": {\"min\": 0,\"title\": {\"text\": \""+yText+"\"}},");
            sb.append("\"tooltip\": {\"headerFormat\": \"<span style='font-size:10px'>{point.key}</span><table>\",\"pointFormat\": \"<tr><td style='color:{series.color};padding:0'>{series.name}: </td><td style='padding:0'><b>{point.y:.1f} "+dw+"</b></td></tr>\",\"footerFormat\": \"</table>\",\"shared\": true,\"useHTML\": true},");
            sb.append("\"plotOptions\": {\"column\": {\"borderWidth\": 0}},");
            sb.append("\"series\": "+series+"");
        sb.append("}");

        return sb.toString();
    }
}

